<template>
  <div class="user-order">
    <Header/>
    <div class="main">
      <div class="banner"></div>
      <div class="profile">
        <div class="profile-info">
          <div class="avatar"><img class="newImg" width="100%" alt="" src="../../static/image/logo@2x.png">
          </div>
          <span class="user-name">吴某某</span>
          <span class="user-job">北京市 | 程序员</span>
        </div>
        <ul class="my-item">
          <li>我的账户</li>
          <li class="active">我的订单</li>
          <li>个人资料</li>
          <li>账号安全</li>
        </ul>
      </div>
      <div class="user-data">
        <ul class="nav">
          <li class="order-info">订单</li>
          <li class="course-expire">有效期</li>
          <li class="course-price">课程价格</li>
          <li class="real-price">实付金额</li>
          <li class="order-status">交易状态</li>
          <li class="order-do">交易操作</li>
        </ul>
        <div class="my-order-item" v-for="(order_value,order_index) in order_data" :key="order_index">
          <div class="user-data-header">
            <span class="order-time">{{order_value.pay_time.replace('T', ' ')}}</span>
            <span class="order-num">订单号：
                <span class="my-older-number">{{order_value.order_number}}</span>
            </span>
          </div>

          <ul class="nav user-data-list" v-for="(course_value,course_index) in order_value.order_courses" :key="course_index">
            <li class="order-info">
              <img :src="course_value.course_img" alt="">
              <div class="order-info-title">
                <p class="course-title">{{course_value.course_name}}</p>
                <p class="price-service">{{course_value.discount_name}}</p>
              </div>
            </li>
            <li class="course-expire">{{course_value.expire_text}}</li>
            <li class="course-price">{{order_value.total_price}}</li>
            <li class="real-price">{{order_value.real_price}}</li>
            <li class="order-status">{{order_value.order_status_name}}</li>
            <li class="order-do">
              <span class="btn btn2" v-if="order_value.order_status===1">去学习</span>
              <span class="btn btn2" v-else-if="order_value.order_status===0" @click="go_pay(order_value.order_number)">去支付</span>
              <span class="btn btn2" v-else>再次购买</span>
            </li>
          </ul>
        </div>

      </div>
    </div>
    <Footer/>
  </div>
</template>

<script>
import Header from "./common/Header"
import Footer from "./common/Footer"

export default {
  name: "Order",
  data() {
    return {
      order_data:[],
    };
  },
  created() {
    this.get_user_order();

  },
  methods: {
    go_pay(order_number){
      let token = sessionStorage.token || localStorage.token;
      // let p = '?charset=utf-8&out_trade_no=2021010711491881&method=alipay.trade.page.pay.return&total_amount=1329.40&sign=LUVCQ6FZEzZFuC1ZRXug5yjfSs7o5x02N%2BKf90NGwugmd9bGoPwhEi1tFIkld83U97rXv9jmtcsgF7UIIjhjgiYL4cIENeyTcR2b%2BIqtzn2a1gvUvY5XY1OClvv6cc3%2BAWwjBpzRae0jALT5LWL32%2FnogLS1rCJmTRSdw3msw5BCvWdZhQapRyz4T0cL1nC2FmQB%2FUkPMJtcZptQ%2Fwv517hEQQHXkHPqQSoSUcXyQPL9ZGnqNkNyLnGSi1wHfsTbGKP5vuMHVsG4rLOBg46gxZu8CjGOwmD1VzprPLBUtPGziwpKuDhPDJi4Q9LdFe65Wq%2B%2FeL1itksLKtvBq7wNdA%3D%3D&trade_no=2021010722001438620501490997&auth_app_id=2016093000633754&version=1.0&app_id=2016093000633754&sign_type=RSA2&seller_id=2088102177995104&timestamp=2021-01-07%2011%3A49%3A46'
      this.$axios.get(`${this.$settings.host}/payment/list/?order_number=${order_number}`,{
            headers:{
              'authorization': `jwt ${token}`,
            }
          }).then((res)=>{
            location.href=res.data.url;

          }).catch((error)=>{

          })
    },

    get_user_order() {
      // 获取当前登录用户的所有订单
      let token = sessionStorage.token || localStorage.token;
      // let p = '?charset=utf-8&out_trade_no=2021010711491881&method=alipay.trade.page.pay.return&total_amount=1329.40&sign=LUVCQ6FZEzZFuC1ZRXug5yjfSs7o5x02N%2BKf90NGwugmd9bGoPwhEi1tFIkld83U97rXv9jmtcsgF7UIIjhjgiYL4cIENeyTcR2b%2BIqtzn2a1gvUvY5XY1OClvv6cc3%2BAWwjBpzRae0jALT5LWL32%2FnogLS1rCJmTRSdw3msw5BCvWdZhQapRyz4T0cL1nC2FmQB%2FUkPMJtcZptQ%2Fwv517hEQQHXkHPqQSoSUcXyQPL9ZGnqNkNyLnGSi1wHfsTbGKP5vuMHVsG4rLOBg46gxZu8CjGOwmD1VzprPLBUtPGziwpKuDhPDJi4Q9LdFe65Wq%2B%2FeL1itksLKtvBq7wNdA%3D%3D&trade_no=2021010722001438620501490997&auth_app_id=2016093000633754&version=1.0&app_id=2016093000633754&sign_type=RSA2&seller_id=2088102177995104&timestamp=2021-01-07%2011%3A49%3A46'
      this.$axios.get(`${this.$settings.host}/order/data/`,{
        headers:{
          'authorization': `jwt ${token}`,
        }
      }).then((res)=>{
        this.order_data = res.data;
      }).catch((error)=>{

      })

    },
  },
  components: {
    Header,
    Footer,
  }
}
</script>

<style scoped>
.main .banner {
  width: 100%;
  height: 324px;
  background: url(../../static/image/my_bkging.0648ebe.png) no-repeat;
  background-size: cover;
  z-index: 1;
}

.profile {
  width: 1200px;
  margin: 0 auto;
}

.profile-info {
  text-align: center;
  margin-top: -80px;
}

.avatar {
  width: 120px;
  height: 120px;
  border-radius: 60px;
  overflow: hidden;
  margin: 0 auto;
}

.user-name {
  display: block;
  font-size: 24px;
  color: #4a4a4a;
  margin-top: 14px;
}

.user-job {
  display: block;
  font-size: 11px;
  color: #9b9b9b;
}

.my-item {
  list-style: none;
  line-height: 1.42857143;
  color: #333;
  width: 474px;
  height: 31px;
  display: -ms-flexbox;
  display: flex;
  cursor: pointer;
  margin: 41px auto 0;
  -ms-flex-pack: justify;
  justify-content: space-between;
}

.my-item .active {
  border-bottom: 1px solid #000;
}

.user-data {
  width: 1200px;
  height: auto;
  margin: 0 auto;
  padding-top: 30px;
  border-top: 1px solid #e8e8e8;
  margin-bottom: 63px;
}

.nav {
  width: 100%;
  height: 60px;
  background: #e9e9e9;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-align: center;
  align-items: center;
}

.nav li {
  margin-left: 20px;
  margin-right: 28px;
  height: 60px;
  line-height: 60px;
  list-style: none;
  font-size: 13px;
  color: #333;
  border-bottom: 1px solid #e9e9e9;
  width: 160px;
}

.nav .order-info {
  width: 325px;
}

.nav .course-expire {
  width: 60px;
}

.nav .course-price {
  width: 130px;
}

.user-data-header {
  display: flex;
  height: 44px;
  color: #4a4a4a;
  font-size: 14px;
  background: #f3f3f3;
  -ms-flex-align: center;
  align-items: center;
}

.order-time {
  font-size: 12px;
  display: inline-block;
  margin-left: 20px;
}

.order-num {
  font-size: 12px;
  display: inline-block;
  margin-left: 29px;
}

.user-data-list {
  height: 100%;
  display: flex;
}

.user-data-list {
  background: none;
}

.user-data-list li {
  height: 60px;
  line-height: 60px;
}

.user-data-list .order-info {
  display: flex;
  align-items: center;
  margin-right: 28px;
}

.user-data-list .order-info img {
  max-width: 100px;
  max-height: 75px;
  margin-right: 22px;
}

.course-title {
  width: 203px;
  font-size: 13px;
  color: #333;
  line-height: 5px;
  margin-top: -10px;
}

.order-info-title .price-service {
  line-height: 18px;
}

.price-service {
  font-size: 12px;
  color: #fa6240;
  padding: 0 5px;
  border: 1px solid #fa6240;
  border-radius: 4px;
  margin-top: 4px;
  position: absolute;
}

.order-info-title {
  margin-top: -10px;
}

.user-data-list .course-expire {
  font-size: 12px;
  color: #ff5502;
  width: 60px;
  text-align: center;
}

.btn {
  width: 100px;
  height: 32px;
  font-size: 14px;
  color: #fff;
  background: #ffc210;
  border-radius: 4px;
  border: none;
  outline: none;
  transition: all .25s ease;
  display: inline-block;
  line-height: 32px;
  text-align: center;
  cursor: pointer;
}
</style>
